package com.oa.ylms.apps.actions;

import java.util.List;
import java.util.Map;

import com.oa.ylms.apps.business.account.IAccountInfoService;
import com.oa.ylms.apps.business.assess.IAssessCheckService;
import com.oa.ylms.apps.business.goods.IGoodsOrderService;
import com.oa.ylms.apps.business.leave.ILeaveCheckService;
import com.oa.ylms.apps.business.move.IPersonMoveInfoService;
import com.oa.ylms.apps.business.news.INewsInfoService;
import com.oa.ylms.apps.business.notice.INoticeInfoService;
import com.oa.ylms.apps.business.plan.IMessageInfoService;
import com.oa.ylms.apps.business.regulations.IRegulationInfoService;
import com.oa.ylms.apps.constants.assess.IAssessInfoStates;
import com.oa.ylms.apps.entity.account.AccountInfoValue;
import com.oa.ylms.apps.entity.archives.StaffInfoValue;
import com.oa.ylms.apps.entity.assess.AssessInfoValue;
import com.oa.ylms.apps.entity.goods.GoodOrderValue;
import com.oa.ylms.apps.entity.leave.LeaveInfoValue;
import com.oa.ylms.apps.entity.move.PersonMoveInfoValue;
import com.oa.ylms.apps.entity.news.NewsInfoValue;
import com.oa.ylms.apps.entity.notice.NoticeInfoValue;
import com.oa.ylms.apps.entity.notice.NoticeSectionValue;
import com.oa.ylms.apps.entity.notice.NoticeStaffValue;
import com.oa.ylms.apps.entity.regulations.RegulationInfoValue;

@SuppressWarnings("serial")
public class LoginAction extends BasicAction {
	private INewsInfoService newsService;
	private IRegulationInfoService regulationService;
	private INoticeInfoService noticeService;
	private List<NewsInfoValue> newsList;
	private List<RegulationInfoValue> regulationList;
	private List<NoticeInfoValue> noticeList;
	
	private ILeaveCheckService leaveService;
	private IAssessCheckService assessService;
	private IGoodsOrderService goodsService;
	private IAccountInfoService accountService;
	private IPersonMoveInfoService moveService;
	
	private IMessageInfoService messageInfoService;
	
	private List<LeaveInfoValue> leaveList;
	private List<AssessInfoValue> assessList;
	private List<GoodOrderValue> goodsList;
	private List<AccountInfoValue> accountList;
	private List<PersonMoveInfoValue> moveList;

	private Map<String, Object > data;
	
	private int messageTotalCount;
	private int messageUnreadCount;
	
	@Override
	public String execute() throws Exception {
		staffInfo = (StaffInfoValue)session.get("login_staffInfo");
		messageTotalCount = messageInfoService.getTotalCount(staffInfo);
		messageUnreadCount = messageInfoService.getUnreadCount(staffInfo);
		return "toMain";
	}
	
	public String messageUnread() throws Exception{
		staffInfo = (StaffInfoValue)session.get("login_staffInfo");
		response.setContentType("text/html; charset=UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		response.getWriter().print(messageInfoService.getUnreadCount(staffInfo));
		return null;
	}
	
	public String login() throws Exception {
		String staffNames = "";
		String sectionNames ="";
		newsList = newsService.queryNewsWithPage(null, null, null, null, 10, 1); 
		regulationList = regulationService.queryRegulationsWithPage(null, null, null, null, 5, 1); 
		noticeList = noticeService.queryTip(); 
		for(NoticeInfoValue noticeInfo : noticeList){
		List<NoticeSectionValue> listSection = noticeService.querySectionDetail(noticeInfo.getNoticeId());
		List<NoticeStaffValue> listStaff = noticeService.queryStaffDetail(noticeInfo.getNoticeId()); 
		for (int i = 0; i < listStaff.size(); i++) {
		if (staffNames == null) {
		staffNames = "";
		}
		staffNames = staffNames
		+ listStaff.get(i).getStaffInfo().getArchiveInfo()
		.getStaffName() + ";";
		}
		noticeInfo.setStaffNames(staffNames);
		for (int i = 0; i < listSection.size(); i++) {
		if (sectionNames == null) {
		sectionNames = "";
		}
		sectionNames = sectionNames
		+ listSection.get(i).getSectionInfo().getSectionName()
		+ ";";
		}
		noticeInfo.setSectionNames(sectionNames);
		}
		return "toLogin";
	}
	
	public String home() throws Exception{
		staffInfo = (StaffInfoValue)session.get("login_staffInfo");
		leaveList = leaveService.queryCheckList(staffInfo, null, 5, currpage);
		assessList = assessService.queryCheckList(staffInfo, IAssessInfoStates.UNDEFINED, IAssessInfoStates.UNDEFINED, null, null, 5, currpage);
		goodsList = goodsService.queryCheckOrder(staffInfo, 5, currpage);
		accountList = accountService.queryAccountCheck(staffInfo, 0);
		moveList = moveService.queryMoveCheck(staffInfo, 5, currpage);
		return "toHome";
	}
	
	public String logout() throws Exception{
		session.put("login_staffInfo", null);
		return "toLogin";
	}
	 
//	private void clearLongContentNews(List<NewsInfoValue> newsList2) {
//		for (NewsInfoValue newsInfoValue : newsList2) { 
//			newsInfoValue.setContent("");
//		}
//	}
//
//	private void clearLongContentReg(List<RegulationInfoValue> regulationList2) {
//	   for (RegulationInfoValue regulationInfoValue : regulationList2) {
//		regulationInfoValue.setContent("");
//	   }
//	}

//	public void loadData() throws Exception
//	{
//		newsList = newsService.queryNewsWithPage(null, null, null, null, 10, 1);
//		regulationList = regulationService.queryRegulationsWithPage(null, null, null, null, 5, 1);
//		//noticeList = noticeService.queryTip();
//		
//		clearLongContentNews(newsList);
//		
//		clearLongContentReg(regulationList);
//		
//		data.put("newsList", newsList); 
//		data.put("regulationList", regulationList); 
//		data.put("noticeList", noticeList);
//		
//		
//		JSONObject json = JSONObject.fromObject(data); 
//		String str =  json.toString() ;
//		System.out.println(str);
//		response.setContentType("text/html; charset=gb2312");
//		response.setHeader("Cache-Control", "no-cache");
//		
//		try {
//			response.getWriter().print(str);
//		} catch (IOException e) {
//			e.printStackTrace();
//		} 
//	}

	public void setNewsService(INewsInfoService newsService) {
		this.newsService = newsService;
	}

	public INewsInfoService getNewsService() {
		return newsService;
	}

	public void setRegulationService(IRegulationInfoService regulationService) {
		this.regulationService = regulationService;
	}

	public IRegulationInfoService getRegulationService() {
		return regulationService;
	}

	public void setNoticeService(INoticeInfoService noticeService) {
		this.noticeService = noticeService;
	}

	public INoticeInfoService getNoticeService() {
		return noticeService;
	}

	public void setNewsList(List<NewsInfoValue> newsList) {
		this.newsList = newsList;
	}

	public List<NewsInfoValue> getNewsList() {
		return newsList;
	}

	public void setRegulationList(List<RegulationInfoValue> regulationList) {
		this.regulationList = regulationList;
	}

	public List<RegulationInfoValue> getRegulationList() {
		return regulationList;
	}

	public void setNoticeList(List<NoticeInfoValue> noticeList) {
		this.noticeList = noticeList;
	}

	public List<NoticeInfoValue> getNoticeList() {
		return noticeList;
	}

	public void setData(Map<String, Object > data) {
		this.data = data;
	}

	public Map<String, Object > getData() {
		return data;
	}

	public ILeaveCheckService getLeaveService() {
		return leaveService;
	}

	public void setLeaveService(ILeaveCheckService leaveService) {
		this.leaveService = leaveService;
	}

	public IAssessCheckService getAssessService() {
		return assessService;
	}

	public void setAssessService(IAssessCheckService assessService) {
		this.assessService = assessService;
	}

	public IGoodsOrderService getGoodsService() {
		return goodsService;
	}

	public void setGoodsService(IGoodsOrderService goodsService) {
		this.goodsService = goodsService;
	}

	public IAccountInfoService getAccountService() {
		return accountService;
	}

	public void setAccountService(IAccountInfoService accountService) {
		this.accountService = accountService;
	}

	public IPersonMoveInfoService getMoveService() {
		return moveService;
	}

	public void setMoveService(IPersonMoveInfoService moveService) {
		this.moveService = moveService;
	}

	public IMessageInfoService getMessageInfoService() {
		return messageInfoService;
	}

	public void setMessageInfoService(IMessageInfoService messageInfoService) {
		this.messageInfoService = messageInfoService;
	}
	
	public List<LeaveInfoValue> getLeaveList() {
		return leaveList;
	}

	public void setLeaveList(List<LeaveInfoValue> leaveList) {
		this.leaveList = leaveList;
	}

	public List<AssessInfoValue> getAssessList() {
		return assessList;
	}

	public void setAssessList(List<AssessInfoValue> assessList) {
		this.assessList = assessList;
	}

	public List<GoodOrderValue> getGoodsList() {
		return goodsList;
	}

	public void setGoodsList(List<GoodOrderValue> goodsList) {
		this.goodsList = goodsList;
	}

	public List<AccountInfoValue> getAccountList() {
		return accountList;
	}

	public void setAccountList(List<AccountInfoValue> accountList) {
		this.accountList = accountList;
	}

	public List<PersonMoveInfoValue> getMoveList() {
		return moveList;
	}

	public void setMoveList(List<PersonMoveInfoValue> moveList) {
		this.moveList = moveList;
	}

	public int getMessageTotalCount() {
		return messageTotalCount;
	}

	public void setMessageTotalCount(int messageTotalCount) {
		this.messageTotalCount = messageTotalCount;
	}

	public int getMessageUnreadCount() {
		return messageUnreadCount;
	}

	public void setMessageUnreadCount(int messageUnreadCount) {
		this.messageUnreadCount = messageUnreadCount;
	}
	
	
	
}
